home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 40
/
Commodore_Free_Issue_40_2010_Commodore_Computer_Club.d64
/
asteroid belt
< prev
next >
Wrap
Text File
|
2023-02-26
|
4KB
|
178 lines
*************************************
COMMODORE FREE BASIC PROGRAMMING
CHALLENGE
C64/VIC20/C16/+4 Version
By Paul Davis
*************************************
Here are a few simple changes to the
Asteroid Belt listing presented in
issue 37. The extra code allows the
game to run on either the C64,
unexpanded VIC20, C16 or Plus/4 and
will detect which machine it is
running on. To make the game
slightly more challenging, an extra
feature has been added that will
deplete the ship's fuel over time.
Run out of fuel and its game over.
Only the lines that need to change
are listed here. Load in the
original program (or copy and paste
it into an emulator) then add the
following lines (owners of an
unexpanded VIC20 will need to remove
some of the old REM comment lines
first to free up some memory):
10 a=0: b=a: c=a: i=a: s=a: f=40:
a$=""
19 rem determine which machine this
is running on
20 if peek(65532)=226 then m=64
21 if peek(65532)=34 then m=20
22 if peek(65532)=246 then m=16
29 rem variables for platform
dependent memory locations
30 if m=64 then
sc=1024:co=55296:wi=40:hg=25
31 if m=20 then
sc=7680:co=38400:wi=22:hg=23
32 if m=16 then
sc=3072:co=2048:wi=40:hg=25
90 gosub 420
100 fori=1 to hg-1:print:nexti
110
b=sc+wi*int(hg/2):c=int(wi/2):bs=sc+w
i*(hg-1)
120 a=int(wi*rnd(1))
130 poke bs+a,46
140 if rnd(1)>.1 then
p=int(rnd(1)*wi):poke p+bs,42
160 if a$="m" and c<wi then poke
b+c,32:c=c+1
171 rem to make the game more
challenging we will use up 1 unit
172 rem of fuel every time the
screen scrolls
173 print:f=f-1
174 rem if we have run out of fuel,
game over
175 if f=0 then r$="ran out of
fuel":goto 310
180 if peek(b+c)=42 then r$="hit an
asteroid":goto 310
320 print "sorry you"
325 print r$
330 print:print "you
scored";s;"points"
400 if m=64 then for i=0 to 16:poke
53280,i:next i
401 if m=20 then for i=0 to 8:poke
36879,i:next i
402 if m=16 then for i=0 to 16:poke
65305,i:next i
405 s=s+10:f=f+10:return
419 rem clear screen to white on
black
420 if m=64 then poke 53280,0:poke
53281,0
421 if m=20 then poke 36879,8
422 if m=16 then poke 65305,0:poke
65301,0
425 print chr$(5);chr$(147);:return
Explanation of the additional lines:
Line 10: adds the F variable to hold
the current amount of fuel on board
the ship.
Lines 20-22: determine which machine
the program is running on by
checking the 6502 reset vector at
memory location 65532 (FFFC in hex).
The end result is that the variable
M is set to the value 64, 20 or 16
for C64, VIC20 or C16/Plus4
respectively.
Lines 30-32: set the value of a few
constants depending on which machine
is in use. SC is the start of screen
memory, CO is the start of colour
memory, WI and HG are the width and
height of the screen. The values for
the VIC20 are for an unexpanded
machine only. If you have extra
memory, the location of the screen
and colour data will need to change.
Line 90: changed to call a
subroutine to clear the screen.
Line 100: changed to use the HG
(screen height) variable rather than
the C64 specific value.
Line 110: changed to use the SC, WI
and HG variables to calculate the
on-screen positions rather than the
C64 specific values. Also added the
BS variable to hold the address of
the bottom screen line.
Line 120,130,140,160: changed to use
the WI and BS variables rather than
the C64 specific values.
Line 173: scroll the screen and
deplete the ship's fuel reserve.
Line 175: check if the fuel has run
out. If it has, jump to the
game-over section with the reason
why the game ended in the R$
variable.
Line 180: changed to put the reason
for ending the game in the R$
variable.
Lines 320-330: changed to print the
reason why the game ended from the
R$ variable. This allows the same
section of code to be used,
regardless of why the game is over.
Lines 400-405: changed to have a
different effect depending on which
machine is in use. The code that is
the same for all machines is on line
405. Collecting a fuel pod increases
the ship's fuel reserve by 10 units.
Lines 420-425: clear the screen to
white on black using the correct
video chip registers for each
machine. The code common to all
machines is on line 425.
=====================================